from django import template
from catalog.models import BookInstance
register = template.Library()

@register.filter
def has_borrowed(user, book):
    if not user.is_authenticated:
        return False
    return BookInstance.objects.filter(book=book, borrower=user, status='o').exists()
